package com.dormitory.Service;


import com.dormitory.dao.UserConnect;
import com.dormitory.dao.UserConnectimpl;
import com.dormitory.entity.User;
import com.dormitory.entity.UserLogin;


public class UserLoginService implements UserService {
    private UserConnect userConnect = new UserConnectimpl();
    @Override
    public UserLogin login(String username, String password){
        User user = this.userConnect.findByUsername(username);
        UserLogin userLogin = new UserLogin();
        if (user == null){
            userLogin.setCode(-1);
        }else {
            if (!user.getPassword().equals(password)){
                userLogin.setCode(-2);
            }else {
                userLogin.setCode(0);
                userLogin.setUser(user);
                userLogin.setLimit(user.getLimit());
                userLogin.setName(user.getName());
            }
        }
        return  userLogin;
    }

}
